package com.graduation.mybatis.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.graduation.mybatis.bean.Food;
import com.graduation.mybatis.service.FoodService;
import com.graduation.mybatis.mapper.FoodMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 23726
* @description 针对表【food】的数据库操作Service实现
* @createDate 2025-03-29 19:55:38
*/
@Service
public class FoodServiceImpl extends ServiceImpl<FoodMapper, Food>
    implements FoodService{

    @Autowired
    private FoodMapper foodMapper;

    @Override
    public List<Food> queryByCategory(String category) {
        return foodMapper.selectByCategory(category);
    }

    /**
     * 分页查询用户
     *
     * @param currentPage 当前页码
     * @param pageSize    每页显示条数
     * @return 分页结果
     */
    public IPage<Food> getFoodPage(int currentPage, int pageSize) {
        // 创建分页对象
        Page<Food> page = new Page<>(currentPage, pageSize);
        // 执行分页查询
        return this.page(page);
    }

    @Override
    public List<Food> searchFoods(String keyword) {
        if (keyword == null || keyword.trim().isEmpty()) {
            throw new IllegalArgumentException("搜索关键字不能为空");
        }
        return foodMapper.searchFoodsByKeyword(keyword.trim());
    }
}




